package zjut.cocouml.editpolicy;

import java.util.Map;

import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.AbstractEditPolicy;

import zjut.cocouml.command.BAttributeModifyCommand;

public class ModifyAttributePolicy extends AbstractEditPolicy {
	
	public Command getCommand(Request request) {
		
		if (request.getType().equals("modifyAttribute")) {
			System.out.println("ModifyAttributePolicy...getCommand.." + request);
			return createModifyAttributeCommand(request);
		}
		return null;
	}
	
	protected Command createModifyAttributeCommand(Request request) {
		BAttributeModifyCommand command = new BAttributeModifyCommand();
		command.setModel(getHost().getModel());
		
		Map map = request.getExtendedData();
		//System.out.println("AppModifyAttributePolicy: newAttributeName == "+(String)request.getExtendedData().get("newAttributeName"));
		command.setNewAttrName((String)map.get("name"));
		command.setNewAccessAuthrity((String)map.get("accessAuthrity"));
		command.setNewType((String)map.get("type"));
		command.setNewFinal((Boolean)map.get("isFinal"));
		command.setNewStatic((Boolean)map.get("isStatic"));
		return command;
	}
}
